package com.cwj.film.controller;

import com.cwj.common.domain.film;
import com.cwj.common.vo.Result;
import com.cwj.common.vo.film.reviewSo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/review")
public class reviewController {

    @Resource
    private com.cwj.film.service.inter.review review;
    @PostMapping("/GetFilmListByType")
    private Result GetFilmListByType(reviewSo reviewSo) throws InvocationTargetException, IllegalAccessException {
        List<film> films = review.GetFilmListByType(reviewSo.getType(), reviewSo.getSize());
        films=films.stream().sorted(Comparator.comparing(film::getFid)).collect(Collectors.toList());

        return Result.normal(films,null);
    }
    @PostMapping("/GetFilmSize")
    private Result GetFilmSize(reviewSo reviewSo){
        Integer size = review.GetFilmSize(reviewSo.getType());
        return Result.normal(size,null);
    }
    @PostMapping("/GetFilmListByPageType")
    private Result GetFilmListByPageType(reviewSo reviewSo) throws InvocationTargetException, IllegalAccessException {

        List<film> films = review.GetFilmListByPageType(reviewSo.getType(), reviewSo.getSize(), reviewSo.getPage());
        films=films.stream().sorted(Comparator.comparing(film::getFid)).collect(Collectors.toList());

        return Result.normal(films,null);
    }

}
